import fs from 'fs';

function u8(buffer) {
    if(typeof buffer === 'string') {
        return Buffer.from(buffer).readUInt8LE(0);
    }
    return new Uint8Array(buffer, buffer.byteOffset, buffer.length);
}

function read32(p) {
    var bytes = new Int32Array(p);

    return (
        (bytes[0] << 0) |
        (bytes[1] << 8) |
        (bytes[2] << 16) |
        (bytes[3] << 24)
    );
}


function readfile(path){
    return new Uint8Array(fs.readFileSync(path)).buffer;
}

const ELF_MAGIC = 0x464C457F;
export function loadProgram(prog) {
    console.log(`Loading program: ${prog}`);

    const progBytes = readfile(prog)

    console.log(progBytes)
    console.log(u8("\x177ELF"))
}